package com.woniu.humanresource.controller;


import com.woniu.humanresource.entity.Blacklist;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.ResponseText;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.BlacklistService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@RestController
public class BlacklistController {

    @Resource
    BlacklistService blacklistService;
    //分页查询黑名单信息
    @PostMapping("/blacklist/{pageIndex}/{pageSize}")
    public ResponseText<PageBean<Blacklist>> getBlacklists(@PathVariable("pageIndex") int page,
                                                         @PathVariable("pageSize") int pageSize,
                                                         @RequestBody Blacklist blacklist){
        ResponseText<PageBean<Blacklist>> responseText=null;
        try {

            PageBean<Blacklist> pageBean = blacklistService.selectCondition(blacklist, page, pageSize);
            responseText=new ResponseText<PageBean<Blacklist>>(pageBean,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
    //添加黑名单信息
    @PostMapping("/blacklist")
    public ResponseText addBlacklist(@RequestBody Blacklist blacklist){
        ResponseText responseText=null;
        try {
            //待面试状态
            blacklist.setTime(new Date());
            blacklistService.insertBlacklist(blacklist);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //删除黑名单人员信息
    @DeleteMapping("/blacklist/{id}")
    public ResponseText deleteBlacklist(@PathVariable("id") int id){
        ResponseText responseText=null;
        try {
            blacklistService.deleteBlacklist(id);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }
}
